#include <iostream>
#include <ctime>
#include <string>
#include <boost/asio.hpp>

using namespace std;
using boost::asio::ip::tcp;

string make_daytime_string()
{
    time_t now = time(0);
    return ctime(&now);
}

int main(int argc, char const *argv[])
{
    try
    {
        boost::asio::io_service service;
        tcp::acceptor           acceptor(service, tcp::endpoint(tcp::v4(), 12345));

        for (;;)
        {
            tcp::socket socket(service);
            acceptor.accept(socket);

            string message = make_daytime_string();

            boost::system::error_code ignored_error;
            boost::asio::write(socket, boost::asio::buffer(message), ignored_error);
        }
    }
    catch (std::exception &e)
    {
        cerr << e.what() << endl;
    }
    return 0;
}
